﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;

public partial class Controls_ControlTimKiemRight : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            cboNoiDi.SelectedIndex = 0;
            TabContainer1.ActiveTabIndex = 0;
            BindCatalog.BindNoiDi(cboNoiDi2);
            BindCatalog.BindNoiDi(cboNoiDi);
            BindCatalog.BindGiaTour(cboGiaTour);
            BindCatalog.BindHangMayBay(cboHang);
            rabtrongnuoc_CheckedChanged(sender, e);
            rabtrongnuoc2_CheckedChanged(sender, e);
            loopDay();
            loopThang();
        }
    }
  
    protected void rabtrongnuoc_CheckedChanged(object sender, EventArgs e)
    {
        TList<NoiDen> TList_Catalogs = DataRepository.NoiDenProvider.Find("IdLoaiTour=1");
        cboNoiDen.DataSource = TList_Catalogs;
        cboNoiDen.DataTextField = "TenNoiDen";
        cboNoiDen.DataValueField = "Id";
        cboNoiDen.DataBind();
        loopNam();
    }

    protected void rabtrongnuoc2_CheckedChanged(object sender, EventArgs e)
    {
        TList<NoiDen> TList_Catalogs = DataRepository.NoiDenProvider.Find("IdLoaiTour=1");
        cboNoiDen2.DataSource = TList_Catalogs;
        cboNoiDen2.DataTextField = "TenNoiDen";
        cboNoiDen2.DataValueField = "Id";
        cboNoiDen2.DataBind();
       
    }

    protected void loopDay()
    {
        cboNgay.Items.Add(new ListItem("Ngày", "0"));
        for(int i=1; i<=31;i++)
        {
            cboNgay.Items.Add(new ListItem(i.ToString(), i.ToString()));            
        }
    }

    protected void loopThang()
    {
        cboThang.Items.Add(new ListItem("Tháng", "0"));
        for (int i = 1; i <= 12; i++)
        {
            cboThang.Items.Add(new ListItem(i.ToString(), i.ToString()));            
        }
    }

    protected void loopNam()
    {
        cboNam.Items.Add(new ListItem("Năm", "0"));
        for (int i = 2020; i >= 1900; i--)
        {
            cboNam.Items.Add(new ListItem(i.ToString(), i.ToString()));            
        }
    }
        
    protected void rabnuocngoai_CheckedChanged(object sender, EventArgs e)
    {    
        TList<NoiDen> TList_Catalogs = DataRepository.NoiDenProvider.Find("IdLoaiTour=2");
        cboNoiDen.DataSource = TList_Catalogs;
        cboNoiDen.DataTextField = "TenNoiDen";
        cboNoiDen.DataValueField = "Id";
        cboNoiDen.DataBind();
    }

    protected void rabnuocngoai2_CheckedChanged(object sender, EventArgs e)
    {
        TList<NoiDen> TList_Catalogs = DataRepository.NoiDenProvider.Find("IdLoaiTour=2");
        cboNoiDen2.DataSource = TList_Catalogs;
        cboNoiDen2.DataTextField = "TenNoiDen";
        cboNoiDen2.DataValueField = "Id";
        cboNoiDen2.DataBind();
    }

    protected void cmdTimKiem_Click(object sender, ImageClickEventArgs e)
    {
       if(rabtrongnuoc.Checked==true)
           Response.Redirect("~/" + cboNoiDi.SelectedValue + "_" + cboNoiDen.SelectedValue + "_" + cboGiaTour.SelectedValue + "_" + cboNgay.SelectedValue + "-" + cboThang.SelectedValue + "-" + cboNam.SelectedValue + "_1" + "_ListTour.aspx");
       if (rabnuocngoai.Checked == true)
           Response.Redirect("~/" + cboNoiDi.SelectedValue + "_" + cboNoiDen.SelectedValue + "_" + cboGiaTour.SelectedValue + "_" + cboNgay.SelectedValue + "-" + cboThang.SelectedValue + "-" + cboNam.SelectedValue + "_0" + "_ListTour.aspx");        
    }

    protected void cmdTimKiemMayBay_Click(object sender, ImageClickEventArgs e)
    {
        if (txtGiaMayBay.Text == "")
            txtGiaMayBay.Text = "0";
        if (rabtrongnuoc.Checked == true)
            Response.Redirect("~/" + "ListAir/" + cboNoiDi2.SelectedValue + "/" + cboNoiDen2.SelectedValue + "/" + cboHang.SelectedValue + "/" + txtGiaMayBay.Text + ".aspx");
        if (rabnuocngoai.Checked == true)
            Response.Redirect("~/" + "ListTour/" + cboNoiDi2.SelectedValue + "/" + cboNoiDen2.SelectedValue + "/" + cboHang.SelectedValue + "/" + txtGiaMayBay.Text + ".aspx");
    }

    protected void cboNam_SelectedIndexChanged(object sender, EventArgs e)
    {
        TabContainer1.ActiveTabIndex = 0;
    }

    protected void cmdSearch_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/" + "ListChuyenMuc/" + Common.ConvertToUnSign(txtTuKhoa.Text) + ".aspx");
    }

    protected void cmdDanhSach_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/ListTour.aspx");
    }

    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {

        if (TabContainer1.ActiveTabIndex == 4)
            Response.Redirect("~/Tim-Kiem-Van-Chuyen.aspx");
    }

    ///// <summary>
    ///// Xu ly su kien Nam thay doi
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void cboNam_SelectedIndexChanged1(object sender, EventArgs e)
    //{

    //}

    ///// <summary>
    ///// Xu ly su kien thang thay doi
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void cboThang_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    string thang = cboThang.SelectedValue;
    //    string nam = cboNam.SelectedValue;

    //    // Neu thang = 0 || hoac nam = 0 thi ngay cu de y vay :)
        
    //}
}